// 组件操作相关
import { defineAsyncComponent, type AsyncComponentLoader, type AsyncComponentOptions } from "vue";
import loading2 from "@/components/loading/loading2.vue";

export const loadAsyncComponent = (loader:AsyncComponentLoader<any>)=>{
    return defineAsyncComponent({
        loader, //加载的组件
        loadingComponent:loading2, //未加载完成之前显示的loading
        delay:20
    })
}

export const fetchCompModule = (type:string,modules:Record<string,{default:string}>)=>{
    for (const key in modules) {
        const moduleName = key.split('/').pop()?.replace('.vue','')
        const module = modules[key]
        if(moduleName == type){
            return module.default
        }
    }
}

// 注册组件
export const initWidget = (type:string,module:string)=>{
    // @ts-ignore
    if(!window['$vue'].component(type)){
        // @ts-ignore
        window['$vue'].component(type,module)
    }
}